package com.guochenglang.www.dao.impl;

import com.guochenglang.www.dao.UserDao;
import com.guochenglang.www.pojo.User;
import com.guochenglang.www.util.GetTable;
import com.guochenglang.www.util.connect.JdbcUtil;

import java.sql.SQLException;
import java.util.ArrayList;

/**
 * 用户表的Dao层
 *
 * @author 郭程朗
 */
public class UserDaoImpl implements UserDao {
    /**
     * 表名
     */
    private static final String TABLE = GetTable.getTable(User.class);

    public UserDaoImpl() {
    }

    @Override
    public ArrayList<User> userSelect(User user) throws SQLException, IllegalAccessException, InstantiationException, InterruptedException {
        return JdbcUtil.selectMax(TABLE, user);
    }

    @Override
    public ArrayList<User> userSelectByLimit(int page, int num, User user, String order, String mode) throws SQLException, InterruptedException, IllegalAccessException, InstantiationException {
        return JdbcUtil.selectByLimit(TABLE, page, num, user, order, mode);
    }


    @Override
    public int insertUser(User user) throws SQLException, InterruptedException, IllegalAccessException {
        return JdbcUtil.insert(TABLE, user);
    }

    @Override
    public int updateUser(User set, User conditions) throws SQLException, InterruptedException, IllegalAccessException {
        return JdbcUtil.update(TABLE, set, conditions);
    }

    @Override
    public int deleteUser(User conditions) throws SQLException, InterruptedException, IllegalAccessException {
        return JdbcUtil.delete(TABLE, conditions);
    }
}
